﻿@using ZR.CodeGenerator
@using ZR.Model.System.Generate
@using Infrastructure.Extensions;
@using Microsoft.AspNetCore.Mvc.Rendering
@using Microsoft.AspNetCore.Mvc.ViewFeatures
@* @model ZR.CodeGenerator.Model.GenerateDto; *@
@{
    var genTable = Model.GenTable;
    var genTableOptions = genTable.Options;
    List<GenTableColumn> listCols = genTable.ListItemColumns;
    List<GenTableColumn> opeFormCols = genTable.OpeFormColumns;
    List<GenTableColumn> formCols = genTable.FormColumns;
    List<GenTableColumn> queryFormCols = genTable.QueryFormColumns;

    var funCodeFirstLower = genTable.FunctionCode.FirstLowerCase();
    var isShowLeftTree = genTableOptions.IsShowLeftTree;
    var isTreeTableShowTree = genTableOptions.IsTreeTable && isShowLeftTree;

    string leftTreeDataName = null;
    string leftTreeApiName = null;
    string leftTreeApiImport = null;
    if (isShowLeftTree)
    {
        if (genTableOptions.LeftTreeComponent == "self")
        {
            leftTreeDataName = $"{funCodeFirstLower}TreeOptions";
            leftTreeApiName = $"get{genTable.FunctionCode}TreeSelectList";
        }
        else
        {
            leftTreeDataName = $"{genTableOptions.LeftTreeComponent}TreeOptions";
            switch (genTableOptions.LeftTreeComponent)
            {
                case "company":
                    leftTreeApiName = "getCompanyTreeSelectList";
                    leftTreeApiImport = "import { getCompanyTreeSelectList } from '@/api/baseFrame/base/company'";
                    break;
                case "dept":
                    leftTreeApiName = "getDepartTreeSelectList";
                    leftTreeApiImport = "import { getDepartTreeSelectList } from '@/api/baseFrame/base/depart'";
                    break;
                case "company_depart":
                    leftTreeApiName = "getOrgTreeSelectList";
                    leftTreeApiImport = "import { getOrgTreeSelectList } from '@/api/baseFrame/depart'";
                    break;
                default:
                    break;
            }
        }
    }

    var idFieldNameFirstLower = genTable.PkFieldName.FirstLowerCase();
    var subTableOptions = Model.SubTableOptions;
    var replaceDto = Model.ReplaceDto;
    bool showCustomInput = Model.GenTable.Columns.Any((Func<GenTableColumn, bool>)(f => f.HtmlType.Equals(GenConstants.HTML_CUSTOM_INPUT, StringComparison.OrdinalIgnoreCase)));
    var index = 0;
    var dictHtml = new string[] { GenConstants.HTML_CHECKBOX, GenConstants.HTML_RADIO, GenConstants.HTML_RADIO_BTN, GenConstants.HTML_SELECT, GenConstants.HTML_SELECT_MULTI };
    var dicts = new List<GenTableColumn>();
    dicts.AddRange(Model.GenTable.Columns.FindAll((Predicate<GenTableColumn>)(f => dictHtml.Contains(f.HtmlType))));
    if (Model.GenTable.SubTable != null && Model.GenTable.SubTableName.IsNotEmpty())
    {
        dicts.AddRange(Model.GenTable?.SubTable?.Columns?.FindAll((Predicate<GenTableColumn>)(f => dictHtml.Contains(f.HtmlType))));
    }
    var customCtls = opeFormCols.Where(m => m.HtmlType == "customCtl").Distinct().ToList();
    var iconCtls = formCols.Where(m => m.HtmlType == "icon").Distinct().ToList();
    var isHasIconCtl = iconCtls.Count > 0;
}

    <div class="app-container">
        <el-row :gutter="20">
        @if (isShowLeftTree)
        {
            <el-col :lg="4" :sm="24">
                <div class="head-container">
                    <el-input
                    v-model="treeFilterKeywords"
                    placeholder="请输入关键词"
                    clearable
                    prefix-icon="el-icon-search"
                    style="margin-bottom: 20px" 
                    />
                </div>
                <div class="head-container">
                    <el-tree :data="@(leftTreeDataName)"
                    :props="defaultTreeProps"
                    :expand-on-click-node="false"
                    :filter-node-method="filterNode"
                    ref="tree"
                    default-expand-all
                    @@node-click="handleNodeClick" 
                    />
                </div>
            </el-col>
        }
            <!--用户数据-->
            <el-col :lg="@(isShowLeftTree?"20":"24")" :sm="24">
                <el-form :model="queryParams" size="small" label-position="right" inline ref="queryForm" v-show="showSearch" 
                        @@submit.native.prevent>
                    <el-form-item label="关键词" prop="keywords">
                        <el-input v-model="queryParams.keywords" placeholder="请输入关键词" clearable />
                    </el-form-item>
@(replaceDto.VueQueryFormHtml)
                    <el-form-item>
                        <el-button type="primary" icon="el-icon-search" size="mini" @@click="handleQuery">搜索</el-button>
                        <el-button icon="el-icon-refresh" size="mini" @@click="resetQuery">重置</el-button>
                    </el-form-item>
                </el-form>
                <el-row :gutter="10" class="mb8">
                    @if(replaceDto.ShowBtnAdd)
                    {
                        <el-col :span="1.5">
                            <el-button type="primary" v-hasPermi="['@(replaceDto.PermissionPrefix):add']" plain icon="el-icon-plus" size="mini" @@click="handleAdd">新增</el-button>
                        </el-col>
                    }
                    @if(replaceDto.ShowBtnEdit)
                    {
                        <el-col :span="1.5">
                            <el-button type="success" :disabled="single" v-hasPermi="['@(replaceDto.PermissionPrefix):edit']" plain icon="el-icon-edit" size="mini" @@click="handleUpdate">修改</el-button>
                        </el-col>
                    }
                    @if(replaceDto.ShowBtnDelete)
                    {
                        <el-col :span="1.5">
                            <el-button type="danger" :disabled="multiple" v-hasPermi="['@(replaceDto.PermissionPrefix):delete']" plain icon="el-icon-delete" size="mini" @@click="handleDelete">删除</el-button>
                        </el-col>
                    }
                    @if(replaceDto.ShowBtnExport)
                    {
                        <el-col :span="1.5">
                            <el-button type="warning" plain icon="el-icon-download" size="mini" @@click="handleExport" v-hasPermi="['@(replaceDto.PermissionPrefix):export']">导出</el-button>
                        </el-col>
                    }
                    <right-toolbar :showSearch.sync="showSearch" @@queryTable="getList"></right-toolbar>
                </el-row>

                <!-- 数据区域 -->
                <el-table :data="dataList" v-loading="loading" ref="table" border highlight-current-row @@sort-change="sortChange" @@selection-change="handleSelectionChange">
                    <el-table-column type="selection" width="50" align="center"/>
@(replaceDto.VueViewListHtml)
                    <el-table-column label="操作" align="center" width="140">
                        <template slot-scope="scope">
                            @if(replaceDto.ShowBtnEdit)
                            {
                                <el-button size="mini" v-hasPermi="['@(replaceDto.PermissionPrefix):edit']" type="text" icon="el-icon-edit" title="编辑" 
                                @@click="handleUpdate(scope.row)">编辑</el-button>      
                            }
                            @if(replaceDto.ShowBtnDelete)
                            {
                                <el-button size="mini" v-hasPermi="['@(replaceDto.PermissionPrefix):delete']" type="text" icon="el-icon-delete" title="删除" 
                                @@click="handleDelete(scope.row)">删除</el-button>
                            }
                        </template>
                    </el-table-column>
                </el-table>
                <pagination class="mt10" background :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @@pagination="getList" />

            </el-col>
        </el-row>
        <!-- 添加或修改@(genTable.FunctionName)对话框 -->
        <el-dialog :title="title" :lock-scroll="false" :visible.sync="open" >
            <el-form ref="form" :model="form" :rules="rules" label-width="100px">
                <el-row :gutter="20" style="display: flex; flex-wrap: wrap;">
@(replaceDto.VueViewFormHtml)
                </el-row>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="text" @@click="cancel">取 消</el-button>
                <el-button type="primary" @@click="submitForm">确 定</el-button>
            </div>
        </el-dialog>

    </div>